import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/home/widgets/shanre_details_widgets.dart';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SelectWheelWidget extends StatefulWidget {
  final int initIndex;
  final String title;
  final int count;
  final int? number;
  final double? contnetSize;
  final List? datas;
  final Function(int index, dynamic data) callBack;
  const SelectWheelWidget(
      {super.key,
      required this.title,
      required this.initIndex,
      required this.count,
      this.number,
      required this.callBack,
      this.datas,
      this.contnetSize});

  @override
  State<SelectWheelWidget> createState() => _SelectWheelWidgetState();
}

class _SelectWheelWidgetState extends State<SelectWheelWidget> {
  int selectIndex = 0;
  late FixedExtentScrollController controller;
  late List<String> items;

  @override
  void initState() {
    if (widget.number != null) {
      items = List.generate(
          widget.count, (index) => '${(index + 1) * widget.number!}');
    }
    selectIndex = widget.initIndex;
    controller = FixedExtentScrollController(initialItem: selectIndex);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ShareDetailsWidgets.widowBackWidget(
        widget.title,
        Column(mainAxisSize: MainAxisSize.min, children: [
          Stack(alignment: Alignment.center, children: [
            Container(
                child: Container(
                    alignment: Alignment.center,
                    color: Colors.transparent,
                    width: 300.sp,
                    height: 528.sp,
                    child: ListWheelScrollView.useDelegate(
                        itemExtent: 115.sp, // 设置单个项目的高度
                        useMagnifier: true,
                        magnification: 1.5,
                        perspective: 0.01,
                        squeeze: 1.0,
                        overAndUnderCenterOpacity: 0.4,
                        controller: controller,
                        physics: const FixedExtentScrollPhysics(),
                        onSelectedItemChanged: (index) =>
                            setState(() => selectIndex = index),
                        childDelegate: ListWheelChildBuilderDelegate(
                            childCount: widget.count,
                            builder: (BuildContext context, int index) {
                              return Container(
                                  alignment: Alignment.center,
                                  color: Colors.transparent,
                                  child: DefaultText(
                                      widget.datas == null
                                          ? items[index]
                                          : '${widget.datas![index]}',
                                      widget.contnetSize ?? 40.sp,
                                      textColor: selectIndex == index
                                          ? const Color(0xFF23C565)
                                          : const Color(0xCCF9F9F9)));
                            })))),
            Container(
                height: 115.sp,
                child: Column(children: [
                  Image.asset('assets/images/home/set/line_image.png',
                      height: 6.sp),
                  const Expanded(child: SizedBox()),
                  Image.asset('assets/images/home/set/line_image.png',
                      height: 6.sp)
                ]))
          ]),
          DefaultBtn(
                  click: () {
                    widget.callBack(
                        selectIndex,
                        widget.datas == null
                            ? (widget.number ?? 1) * (selectIndex + 1)
                            : widget.datas![selectIndex]);
                  },
                  title: '确认'.tr)
              .marginOnly(bottom: 112.sp)
        ]),
        hitLine: true);
  }
}
